home *** CD-ROM | disk | FTP | other *** search
Text File | 1988-06-22 | 1.5 KB | 68 lines | [TEXT/MPS ] |
- Program Ext_SetSerBuf;
-
- Uses MemTypes,QuickDraw,OSIntf,ToolIntf,
- Packintf;
- {$D+}
- {$R-}
- Var
- BufHandle:Handle;
- PrinterOrModem,NbOfBytes:Integer;
-
- procedure SetSerBuf(
- var PrinterOrModem:Integer;
- var BufHandle:Handle;
- var NbOfBytes:Integer);
-
- var Error,RefNum:Integer;
-
- begin
- {default buffersize of 1024 bytes}
- if NbOfBytes<1 then NbOfBytes:=1024;
- {max buffer size is 32000}
- if NbOfBytes>32000 then
- NbOfBytes:=32000;
- {generate space for the new buffer}
- BufHandle:=NewHandle(Ord4(NbOfBytes));
- {Test for Handle allocation error}
- Error:=MemError;
- if Error=NoErr then
- begin
- {Move Handle out of the way to avoid}
- {fragmentation.}
- MoveHHI(BufHandle);
- {Lock that puppy down}
- HLock(BufHandle);
- {Set Reference Number accordingly.}
- {0 is Printer, 1 is Modem}
- if PrinterOrModem=0 then
- RefNum:=-8 {Printer}
- else
- RefNum:=-6; {Modem}
- {Reassign the serial port buffer} Error:=SerSetBuf(RefNum,Ptr(BufHandle^)
- ,Ord(GetHandleSize(BufHandle)));
- {Test for errors from reassignment}
- if Error<>NoErr then
- begin
- {If errors then beep and undo what we}
- {have done.}
- SysBeep(10);
- {Assign the error code to NbOfBytes}
- {so that it is returned}
- NbOfBytes:=Error;
- {Unlock and dispose of buffer}
- HUnLock(BufHandle); DisposHandle(BufHandle); BufHandle:=Nil;
- end; {if Error<>NoErr}
- end {if Error=NoErr, TRUE}
- else
- begin
- {there was a memory allocation error}
- SysBeep(10);
- NbOfBytes:=Error;
- end; {if Error=NoErr, FALSE}
- end; {SetSerBuf}
-
- Begin
- SetSerBuf(PrinterOrModem,BufHandle,
- NbOfBytes);
- End. {Main Block}
-